﻿cmake_minimum_required(VERSION 3.0)

SET(SOLUTION_NAME OTK)

# Set up CMake to use Solution Folders in VS.
# 否则SET_PROPERTY(TARGET ${PRODUCT_NAME} PROPERTY FOLDER ${SOLUTION_FOLDER_NAME})不起作用。
# 即项目不能按文件夹分类
SET_PROPERTY( GLOBAL PROPERTY USE_FOLDERS ON )
SET_PROPERTY( GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake Targets" )

PROJECT(${SOLUTION_NAME})

# 指定自定义cmake脚本，在CMakeModules文件夹下
SET(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")

# 查找OSG库
FIND_PACKAGE(OSG REQUIRED)
INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
LINK_DIRECTORIES(${OSG_LIB_DIR})

# 查找OSGEARTH库
FIND_PACKAGE(OSGEARTH REQUIRED)
INCLUDE_DIRECTORIES(${OSGEARTH_INCLUDE_DIR})
LINK_DIRECTORIES(${OSGEARTH_LIB_DIR})

# 查找第三方依赖库
FIND_PACKAGE(3rdParty)
IF(3rd_FOUND)
	SET(3rd_INCLUDE_DIR ${3rd_DIR}/include)
	SET(3rd_LIB_DIR ${3rd_DIR}/lib)
	INCLUDE_DIRECTORIES(${3rd_INCLUDE_DIR})
	LINK_DIRECTORIES(${3rd_LIB_DIR})
ENDIF()

# 查找Qt5库。Qt5Widgets_DIR一般选择类似D:/Code/Qt/Qt5.8.0/5.8/msvc2015/lib/cmake/Qt5Widgets目录
FIND_PACKAGE(Qt5Widgets REQUIRED)
IF(Qt5Widgets_FOUND)
	#SET(QT_INCLUDE_DIR ${Qt5Widgets_INCLUDE_DIRS} ${Qt5OpenGL_INCLUDE_DIRS})
ENDIF()

# 使用Qt中的QOpenGLWidget还是使用QGLWidget
OPTION(USE_QOpenGLWidget “使用QOpenGLWidget” OFF)

OPTION(USE_CGAL “使用CGAL用于布尔运算” OFF)
IF(USE_CGAL)
	# 查找CGAL，布尔运算BooleanOperationCGAL需要。注意CGAL5.0开始，默认是head-only模式(即只使用头文件，不用lib和dll)
	FIND_PACKAGE(CGAL)
ENDIF()

OPTION(USE_osgModeling “使用osgModeling用于布尔运算” OFF)
IF(USE_osgModeling)
	# 查找osgModeling，布尔运算BooleanOperationOsgModeling需要
	FIND_PACKAGE(osgModeling)
ENDIF()

# 设置Debug版本和Release版本下库文件的后缀名
SET(CMAKE_DEBUG_POSTFIX "d")
SET(CMAKE_RELEASE_POSTFIX "")

# 添加宏定义函数
INCLUDE(MacroUtils)

# 检查c++编译器标志，设置c++11支持变量
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)

ADD_SUBDIRECTORY(3rd)
ADD_SUBDIRECTORY(osg)
ADD_SUBDIRECTORY(oe)
ADD_SUBDIRECTORY(qt)